package com.deyuanyun.pic.pipe.controller;

import com.deyuanyun.pic.common.dto.PageJsonBean;
import com.deyuanyun.pic.common.util.ajax.AjaxSupport;
import com.deyuanyun.pic.pipe.controller.dto.PipeBaseQuery;
import com.deyuanyun.pic.pipe.controller.vo.SteelPipeVO;
import com.deyuanyun.pic.pipe.enumeration.PipeExportEnum;
import com.deyuanyun.pic.pipe.service.PipeMgrService;
import com.deyuanyun.pic.settings.util.DownExcelUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.List;

/**
 * “钢管信息”控制类
 * 
 * @作者:严祥
 * @创建时间: 2015年9月14日
 * @类名称: PipeSteelController
 * @类说明:钢管信息Controller层
 *
 */
@Controller
@RequestMapping("/pipe/steelPipe")
public class SteelPipeController extends PipeBaseController {

	@Resource
	private PipeMgrService pipeMgrService;

	/**
	 * 跳转到 钢管信息 主页面
	 *
	 * @return
	 */
	@RequestMapping("/toSteelPipe")
	public ModelAndView toSteelPipe(){
		ModelAndView mv=new ModelAndView();
		mv.setViewName("/basedata/pipe/pipeSteel");
		return mv;
	}

	/**
	 * 根据条件分页查询 钢管信息 数组对象
	 *
	 * @param pipeBaseQuery
	 */
	@RequestMapping("/query.json")
	@ResponseBody
	public void query(PipeBaseQuery pipeBaseQuery) {
		PageJsonBean jsonBean = new PageJsonBean();
		jsonBean.setList(this.queryVO(pipeBaseQuery));
		AjaxSupport.sendSuccessText("success", jsonBean);
	}

	/**
	 * 根据条件导出 钢管信息
	 *
	 * @param pipeBaseQuery
	 * @throws IOException
	 */
	@RequestMapping("/export.json")
	@ResponseBody
	public void export(PipeBaseQuery pipeBaseQuery) throws IOException {
		List list = this.queryVO(pipeBaseQuery);
		PipeExportEnum exportEnum = PipeExportEnum.SteelPipe;
		String[] columnKeys = {"pipeLineName", "pipeNumber","manufacturedNum","material","pipeType","manupipeseamType",
				"ugwwId", "dgwwId","stoveserialNum","diameter","wallThickness","pipeLength",
				"coatingMaterial", "coatingSource","interNalorexternal","coatingThickness","testVoltage","pipeManufacturer",
				"pipeManufactureDate","coatingManufacturer","coatingManufactureDate","recorder", "recordTime", "remark"};
		DownExcelUtil.export(exportEnum.getFileName(), pipePath+exportEnum.getTempPath(), exportEnum.getBeginRow(), list, columnKeys);
	}

	private List queryVO(PipeBaseQuery pipeBaseQuery) {
		return new SteelPipeVO().fromDomainList(pipeMgrService.querySteelPipe(pipeBaseQuery));
	}
	
}
